<template>
	<hyb-page :title="base.name">
		<!-- 请开始您的开发 ~ -->

		<!-- 搜索框 -->
		<template v-slot:top v-if="$store.state.base.show_base.is_dingwei == 1 || base.show_base.sy_sousuo == 1">
			<view :style="{background:base.qjcolor}">
				<view class="gui-padding-small gui-flex gui-align-items-center ">
					<view v-if="$store.state.base.show_base.is_dingwei == 1" @tap="to_position()"
						class="gui-flex gui-color-white  gui-align-items-center " style="padding: 10rpx 0">
						<text class="gui-text"
							style="margin-left: 10rpx;">{{$store.state.base.city_type==1?$store.state.xiaoqu.name: $store.state.city}}</text>
						<text class="gui-icons gui-block  gui-text"
							style="margin-left: 10rpx;font-size: 20rpx;">&#xe603;</text>
					</view>

					<view v-if="base.show_base.sy_sousuo == 1 "
						class="gui-flex1 gui-flex gui-align-items-center gui-bg-white"
						style="padding: 10rpx 16rpx;margin-left: 40rpx;border-radius: 40rpx;">
						<input class="gui-flex1 gui-text" v-model="search" style="margin-left: 10rpx;"
							placeholder="请输入服务名称" />
						<text @tap="goSearch()" class="gui-block gui-color-white  gui-text"
							style="margin-left: 10rpx;padding: 5rpx 16rpx; border-radius: 40rpx;"
							:style="{background:base.qjcolor}">搜索</text>
					</view>
				</view>
			</view>

		</template>
		<!-- 轮播图 -->
		<template v-slot:body>

			<!-- 首页图片弹窗 -->
			<gui-popup ref="bindPhone" z-index="1000">
				<!-- 新人领券新人福利新人领券 -->
				<image class="gui-bg-white gui-border-radius" @tap="toPhone()" style="margin: -22rpx;" mode="widthFix"
					:src="$store.state.base.xr_yhq_lq">
				</image>
				<text @tap.stop="closePopup()" style="font-size: 50rpx;bottom: 50rpx;margin: 20rpx;"
					class="gui-block  gui-icons gui-color-white gui-absolute-rt">&#xe78a;</text>
			</gui-popup>

			<view class="main">
				<view
					v-if="($store.state.base.show_base.is_dingwei == 1 || base.show_base.sy_sousuo == 1) && swiperItems.length > 0"
					style="height: 86rpx;">
				</view>

				<!-- 首页轮播 -->
				<view v-if="swiperItems.length > 0"
					:style="{'background-image':'linear-gradient('+$store.state.base.qjcolor + ',#ffffff,#ffffff)',order:sorting.swiper_items}"
					class="gui-padding-middle">
					<gui-swiper :spacing="0" borderRadius="30rpx" :swiperItems="swiperItems" imgMode="scaleToFill"
						:width="710" :height="330">
					</gui-swiper>
				</view>


				<!-- 首页公告 -->
				<view :style="{order:sorting.sy_gongao}" v-if="$store.state.base.sy_gongao"
					class="gui-padding-middle gui-margin-small gui-border-radius-large gui-bg-white gui-relative">
					<text class="gui-icons gui-block gui-color-gray gui-text gui-absolute-lt gui-color-red"
						style="left: 20rpx;top:20rpx;font-size: 40rpx;">&#xe62b;</text>
					<hyb-rich-text :content="$store.state.base.sy_gongao"></hyb-rich-text>
				</view>





				<!-- 分类菜单展示 -->
				<view v-if="tops.length > 0" :style="{order:sorting.tops}">
					<hyb-grid :width="90" class="gui-margin-top-small" :items="tops" :keys="['thumb','title']"
						@item_click="goto"></hyb-grid>
				</view>

				<!-- 资讯 -->
				<view :style="{order:sorting.article_items}" v-if="articleItems.length > 0"
					class="gui-padding-middle gui-bg-white gui-margin-top-small">

					<view class="gui-flex gui-rows gui-nowrap gui-align-items-center gui-padding-x-small">
						<text class="gui-icons gui-title-icon gui-primary-text gui-bold">&#xe614;</text>
						<text class="gui-primary-text gui-h6 gui-flex1">{{base.can_dan_mc[0]}}</text>
						<!-- <navigator url="/hyb_o2o/article/index/index">
							<text class="gui-icons  gui-block gui-text-small gui-color-gray">更多 &#xe601;</text>
						</navigator> -->
					</view>
					<view class="gui-margin-top">
						<gui-swiper :spacing="0" borderRadius="10px" :swiperItems="articleItems" imgMode="scaleToFill"
							:width="710" :height="330">
						</gui-swiper>
					</view>
				</view>



				<!-- 头部菜单，小于5个时显示区域 -->
				<view :style="{order:sorting.second_tops}" v-if="second_tops.length>0 && second_tops.length < 5"
					class="gui-bg-white gui-flex gui-padding-x gui-margin-top-middle gui-align-items-center">
					<view class="gui-flex1">
						<image :style="{height:second_tops.length==3?'265rpx':'120rpx'}"
							style="border-radius: 20rpx;width: 100%;background-color: gray;" class="gui-border-radius"
							@tap="goto(second_tops[0])" :src="second_tops[0].thumb" mode="aspectFill" :key="index">
						</image>

						<image v-if="second_tops.length==4"
							style="border-radius: 20rpx;width: 100%; height: 120rpx; margin-top: 15rpx;background-color: gray;"
							class="gui-border-radius" @tap="goto(second_tops[3])" :src="second_tops[3].thumb"
							mode="aspectFill" :key="index"></image>
					</view>
					<view class="gui-flex1" style="margin-left: 20rpx;" v-if="second_tops.length>1">
						<image style="border-radius: 20rpx;width: 100%; height: 120rpx;background-color: gray;"
							class="gui-border-radius" @tap="goto(second_tops[1])" :src="second_tops[1].thumb"
							mode="aspectFill" :key="index"></image>


						<image v-if="second_tops.length>2"
							style="border-radius: 20rpx;width: 100%; height: 120rpx; margin-top: 15rpx;background-color: gray;"
							class="gui-border-radius" @tap="goto(second_tops[2])" :src="second_tops[2].thumb"
							mode="aspectFill" :key="index"></image>
					</view>
				</view>
				<!-- 头部菜单，大于4个时显示区域 -->
				<view :style="{order:sorting.second_tops}" v-if="second_tops.length>4"
					class="gui-bg-white gui-flex gui-padding-x gui-margin-top-middle gui-align-items-center">
					<!-- 左边列 -->
					<view class="gui-flex1">
						<image v-if="second_tops.length>0" :style="{height:second_tops.length==5?'265rpx':'120rpx'}"
							style="border-radius: 20rpx;width: 100%;background-color: gray;" class="gui-border-radius"
							@tap="goto(second_tops[0])" :src="second_tops[0].thumb" mode="aspectFill" :key="index">
						</image>
						<image v-if="second_tops.length>2"
							style="border-radius: 20rpx;height:120rpx;width: 100%;background-color: gray;"
							class="gui-border-radius" @tap="goto(second_tops[2])" :src="second_tops[2].thumb"
							mode="aspectFill" :key="index"></image>
						<image v-if="second_tops.length>4 && second_tops.length != 5"
							style="border-radius: 20rpx;height:120rpx;width: 100%;background-color: gray;"
							class="gui-border-radius" @tap="goto(second_tops[4])" :src="second_tops[4].thumb"
							mode="aspectFill" :key="index"></image>
						<image v-if="second_tops.length>6"
							style="border-radius: 20rpx;height:120rpx;width: 100%;background-color: gray;"
							class="gui-border-radius" @tap="goto(second_tops[6])" :src="second_tops[6].thumb"
							mode="aspectFill" :key="index"></image>



					</view>
					<!-- 右边列 -->
					<view class="gui-flex1" style="margin-left: 20rpx;" v-if="second_tops.length>4">

						<image v-if="second_tops.length>1"
							style="border-radius: 20rpx;width: 100%; height: 120rpx;background-color: gray;"
							class="gui-border-radius" @tap="goto(second_tops[1])" :src="second_tops[1].thumb"
							mode="aspectFill" :key="index"></image>
						<image v-if="second_tops.length>3"
							style="border-radius: 20rpx;width: 100%; height: 120rpx;background-color: gray;"
							class="gui-border-radius" @tap="goto(second_tops[3])" :src="second_tops[3].thumb"
							mode="aspectFill" :key="index"></image>
						<image v-if="second_tops.length>5"
							style="border-radius: 20rpx;width: 100%; height: 120rpx;background-color: gray;"
							class="gui-border-radius" @tap="goto(second_tops[5])" :src="second_tops[5].thumb"
							mode="aspectFill" :key="index"></image>
						<image v-if="second_tops.length>7  && second_tops.length != 6"
							style="border-radius: 20rpx;width: 100%; height: 120rpx;background-color: gray;"
							class="gui-border-radius" @tap="goto(second_tops[7])" :src="second_tops[7].thumb"
							mode="aspectFill" :key="index"></image>
						<image v-if="second_tops.length== 5"
							style="border-radius: 20rpx;height:120rpx;width: 100%;background-color: gray;"
							class="gui-border-radius" @tap="goto(second_tops[4])" :src="second_tops[4].thumb"
							mode="aspectFill" :key="index"></image>


					</view>

				</view>

				<!-- 中间大图菜单 -->
				<view :style="{order:sorting.pics}" class="gui-bg-white gui-text-center">
					<image style="width: 98%;border-radius: 20rpx;" class="gui-border-radius" @tap="goto(item)"
						:src="item.thumb" mode="widthFix" v-for="(item,index) in pics" :key="index"></image>
				</view>

				<!-- 公告 -->
				<view :style="{order:sorting.notices}" v-if="notices.length > 0"
					class="gui-bg-white gui-padding-x gui-margin-top-small">
					<gui-speaker :items="notices">
						<template v-slot:icon>
							<text class="gui-block gui-icons demo-icon gui-primary-color">&#xe656;</text>
						</template>
					</gui-speaker>
				</view>

				<view :style="{order:sorting.shanjias}" v-if="$store.state.base.show_base.sj_num && shanjias.length>0">
					<view class="gui-flex gui-rows gui-nowrap gui-align-items-center gui-padding">
						<text class="gui-icons gui-title-icon gui-primary-text gui-bold">&#xe614;</text>
						<text class="gui-primary-text gui-h6 gui-flex1">推荐商家</text>
						<navigator url="/hyb_o2o/shangjia/list/list">
							<text class="gui-icons gui-text-small gui-color-gray">更多 &#xe601;</text>
						</navigator>
					</view>


					<navigator v-for="(item,index) in shanjias" :key="index"
						:url="'/hyb_o2o/shangjia/info/info?id=' + item.s_id">
						<view class="gui-list-items gui-bg-white gui-padding-x">
							<view class="gui-relative">
								<image class="gui-list-image" :src="item.s_thumb">
								</image>
							</view>
							<view class="gui-list-body gui-border-b">
								<view class="gui-list-title">
									<text class="gui-list-title-text gui-primary-text">{{item.s_name}}</text>
									<text v-if="item.distance" class="gui-text-small gui-color-gray"
										style="font-size: 24rpx;">距我{{item.distance}}km</text>
								</view>
								<gui-star activecolor="#FBDE4E" fontSize="30rpx" :totalstars="5" :starnum="5"
									:cantap="false">
								</gui-star>
								<view class="gui-list-body-desc">
									<view
										class="gui-flex gui-row gui-nowrap gui-align-items-center gui-overflow-hidden">
										<text style="flex-shrink: 0;">经营范围：</text>
										<template v-if="item.s_types">
											<gui-tags :size="22" style="margin: 0;"
												v-for="(tag,i) in item.s_types.slice(0,2)" :text="tag"
												:customClass="['gui-bg-grey7','gui-color-black','gui-ellipsis']"></gui-tags>
										</template>
									</view>
								</view>
								<text class="gui-list-body-desc">地址：{{item.s_address}}</text>
							</view>
							<text class="gui-list-arrow-right gui-icons">&#xe601;</text>
						</view>
					</navigator>
				</view>
				<view :style="{order:sorting.yuangongs}" class="gui-margin-top-middle" v-if="yuangongs.length>0">
					<view class="gui-flex gui-rows gui-nowrap gui-align-items-center gui-padding-x ">
						<text class="gui-icons gui-title-icon gui-primary-text gui-bold">&#xe614;</text>
						<text class="gui-primary-text gui-h6 gui-flex1">推荐师傅</text>
						<navigator url="/hyb_o2o/jishi/list/list">
							<text class="gui-icons gui-text-small gui-color-gray">更多 &#xe601;</text>
						</navigator>
					</view>
					<!-- 师傅头像小图片 -->
					<navigator v-for="(item,index) in yuangongs" :key="index" v-if="$store.state.base.show_base.yg_tx"
						:url="'/hyb_o2o/jishi/info/info?id=' + item.y_id">
						<view class="gui-list-items gui-bg-white gui-padding-x">
							<view class="gui-relative">
								<image class="gui-list-image" :src="item.y_thumb||$store.state.base.yg_set.yg_lb_tu">
								</image>
							</view>
							<view class="gui-list-body gui-border-b">
								<view class="gui-list-title">
									<text class="gui-list-title-text gui-primary-text">{{item.y_name}}</text>
									<text v-if="item.distance" class="gui-text-small gui-color-gray"
										style="font-size: 24rpx;">距我{{item.distance}}km</text>
								</view>
								<gui-star activecolor="#FBDE4E" fontSize="30rpx" :totalstars="5" :starnum="5"
									:cantap="false">
								</gui-star>
								<view class="gui-list-body-desc">
									<view
										class="gui-flex gui-row gui-nowrap gui-align-items-center gui-overflow-hidden">
										<view class="gui-flex-shrink0">技能：</view>
										<gui-tags :key="index2" :size="20"
											v-for="(jineng,index2) in item.y_jinengs.slice(0,2)" :text="jineng.xt_name"
											:customClass="['gui-bg-gray','gui-color-black','gui-ellipsis']"></gui-tags>
									</view>
								</view>
								<text class="gui-list-body-desc">服务人数：{{item.fw_count}}</text>
							</view>
							<text class="gui-list-arrow-right gui-icons">&#xe601;</text>
						</view>
					</navigator>

					<!-- 师傅头像大图片 -->
					<navigator v-for="(item,index) in yuangongs" :key="index" v-if="!$store.state.base.show_base.yg_tx"
						:url="'/hyb_o2o/jishi/info/info?id=' + item.y_id">
						<view
							class="gui-list-items gui-bg-white gui-padding gui-border-radius-large gui-margin-top-middle">
							<image style="width: 200rpx;height: 260rpx;border-radius: 10rpx;" mode="aspectFill"
								:src="item.y_thumb||$store.state.base.yg_set.yg_lb_tu">
							</image>
							<view class="gui-list-body">
								<view class="gui-list-title">
									<text class="gui-text gui-primary-text gui-ellipsis">{{item.y_name}}</text>
									<text class="gui-text-small gui-color-grey2 bold gui-margin-left"
										v-if="item.distance != null">距我:{{item.distance}}km</text>
								</view>
								<view class="gui-list-body-desc gui-margin-top">
									<view class="gui-flex gui-row gui-nowrap gui-align-items-center  gui-flex1">
										<view>好评：</view>
										<gui-star :activecolor="base.qjcolor" fontSize="30rpx" :totalstars="5"
											:starnum="5" :cantap="false"></gui-star>
									</view>

									<view
										class="gui-flex gui-row gui-nowrap gui-align-items-center  gui-flex1 gui-margin-top-middle">
										<view class="gui-flex-shrink0">技能：</view>
										<gui-tags :key="index2" :size="20"
											v-for="(jineng,index2) in item.y_jinengs.slice(0,2)" :text="jineng.xt_name"
											:customClass="['gui-bg-gray','gui-color-black','gui-ellipsis']"></gui-tags>
									</view>

									<view
										class="gui-flex gui-row gui-nowrap gui-align-items-center gui-space-between  gui-flex1 gui-margin-top-middle">
										<view>服务人数：{{item.fw_count}}</view>
									</view>

								</view>
							</view>
						</view>

					</navigator>



				</view>



				<view :style="{order:sorting.fuwus}" class="gui-margin-top-middle" v-if="fuwus.length>0">
					<view class="gui-flex gui-rows gui-nowrap gui-align-items-center gui-padding-x ">
						<text class="gui-icons gui-title-icon gui-primary-text gui-bold">&#xe614;</text>
						<text class="gui-primary-text gui-h6 gui-flex1">推荐服务</text>
						<!-- <navigator v-if="$store.state.base.sy_gd"
							url="/hyb_o2o/addpages/pages/all/all?tabinex=3&tabbar=1">
							<text class="gui-icons gui-text-small gui-color-gray">更多 &#xe601;</text>
						</navigator> -->
					</view>

					<view class="gui-flex gui-wrap">
						<view style="width:345rpx;margin-left:20rpx;margin-top:20rpx;" v-for="(item,index) in fuwus"
							:key="index">

							<view class="gui-bg-white gui-border-radius-large" style="100%">
								<navigator
									:url="'/hyb_o2o/addpages/pages/detail/detail?id='+ item.x_id + '&g_lbt_cc=' +item.g_lbt_cc">
									<image class="gui-border-top-radius-large" style="width: 100%;height: 340rpx"
										mode="scaleToFill" :src="item.x_thumb"></image>
									<view style="padding-bottom: 12rpx;">
										<view class="gui-text gui-color-black gui-bold gui-margin-small gui-ellipsis">
											{{item.x_name}}
										</view>

										<view class="gui-text-small gui-color-gray gui-margin-small">
											{{item.fadans_count + item.x_xiaoliang}}人下单
										</view>
										<view class="gui-text gui-color-red gui-margin-small gui-bold">
											￥{{item.x_jiage}}{{item.x_danwei}}
										</view>
									</view>
								</navigator>
							</view>

						</view>
					</view>

				</view>

				<view :style="{order:sorting.goods}" class="gui-margin-top-middle" v-if="goods.length>0">
					<view class="gui-flex gui-rows gui-nowrap gui-align-items-center gui-padding-x ">
						<text class="gui-icons gui-title-icon gui-primary-text gui-bold">&#xe614;</text>
						<text class="gui-primary-text gui-h6 gui-flex1">推荐商品</text>
						<!-- <navigator url="/hyb_o2o/subpagesA/pages/sc/sc?tabinex=3&tabbar=1">
							<text class="gui-icons gui-text-small gui-color-gray">更多 &#xe601;</text>
						</navigator> -->
					</view>

					<view class="gui-flex gui-wrap">
						<view style="width:345rpx;margin-left:20rpx;margin-top:20rpx;" v-for="(item,index) in goods"
							:key="index">
							<view class="gui-bg-white gui-border-radius-large" style="100%">
								<navigator :url="'/hyb_o2o/subpagesA/pages/goods/goods?id='+ item.g_id">
									<image class="gui-border-top-radius-large" style="width: 100%;height: 340rpx"
										mode="scaleToFill" :src="item.g_thumb"></image>
									<view style="padding-bottom: 12rpx;">
										<view class="gui-text gui-color-black gui-bold gui-margin-small gui-ellipsis">
											{{item.g_name}}
										</view>

										<view class="gui-text-small gui-color-gray gui-margin-small">
											{{item.g_xiaoliang}}人购买
										</view>
										<view class="gui-text gui-color-red gui-margin-small gui-bold">
											￥{{item.g_jiage}}{{item.g_danwei}}
										</view>
									</view>
								</navigator>
							</view>
						</view>
					</view>
				</view>



				<!-- <view @tap="goto('kefu')"
					style="width:250rpx;z-index: 10000; position: fixed;bottom: 180rpx;left: 55%;margin-left: -150rpx; color: #fff;padding:13rpx 0;border-radius:20rpx;display: flex;align-items: center;justify-content: center;">
					<text style="font-size: 35rpx;font-weight: 800;">售前客服</text>
					<text style="font-size: 24rpx;margin-left: 8rpx;">售后客服</text>
				</view> -->

				<view v-if="$store.state.base.service_types.length > 0"
					style="width: 70rpx;position: fixed;bottom: 200rpx;left: 90%;transform: translateX(-50%);z-index: 9999;">
					<image @tap="openMenuPopup" style="width: 73rpx;height: 73rpx;border-radius: 20%;"
						src="https://xin-jia-zheng-1300612619.cos.ap-chengdu.myqcloud.com/6/1751873761798rHtMEc.png"
						mode="scaleToFill">
					</image>
				</view>
			</view>

			<view v-if="showMenuPopup && $store.state.base.service_types.length > 0" class="fake-popup">
				<view class="popup-content">
					<view style="font-size: 36rpx; font-weight: bold; margin-bottom: 40rpx;">请选择您需要测试的行业内容</view>
					<button v-for="(item, idx) in $store.state.base.service_types" :key="idx" class="menu-btn"
						@tap="handleMenuSelect(item)">
						{{ item }}
					</button>
				</view>
			</view>

		</template>
	</hyb-page>
</template>
<script>
	export default {
		data() {
			return {
				swiperItems: [],
				articleItems: [],
				tops: [],
				second_tops: [],
				notices: [],
				shanjias: [],
				goods: [],
				fuwus: [],
				yuangongs: [],
				pics: [],
				address: {},
				// is_index:0,
				search: "",
				showMenuPopup: false,
			}
		},

		computed: {
			base: () => {
				return uni.storage.get("base");
			},
			userinfo: () => {
				return uni.storage.get("userinfo");
			},

			sorting: function() {
				return this.$store.state.base.sorting || {}
			}
		},

		created() {
			// 先确保基础数据已加载
			this.$store.state.base.show_base = uni.storage.get("base")?.show_base || {};

			// 加载各类数据
			if (this.$store.state.base.show_base.sy_sfxslbt) this.get_swipers(); //轮播图
			if (this.$store.state.base.show_base.sy_sfxsxcd) this.get_tops(); //分类菜单展示
			if (this.$store.state.base.show_base.sy_sfxsgg) this.get_notices(); //公告
			if (this.$store.state.base.show_base.sy_sfxsdtcd || this.$store.state.base.show_base.shenhe_uniacid == 1) this
				.get_pics(); //大图菜单
			if (this.$store.state.base.show_base.fw_num) this.get_tuijian_fuwu(); //服务
		
		},


		// watch: {
		// 	'$store.state.base'() {
		// 		this.dingwei();
		// 	}
		// },

		onLoad() {
			// this.dingwei();
			if (!uni.storage.get("base")) {
				uni.navigateTo({
					url: '/hyb_o2o/index/index'
				})
			}
			if (this.$store.state.base.xr_yhq_lq && this.$store.state.userinfo && this.$store.state.userinfo.xin_yh && !uni
				.storage.get("tc_tag")) {
				this.$nextTick(() => {
					this.$refs.bindPhone.open();
				})
			}

		},


		methods: {
			toPhone() {
				uni.storage.set("tc_tag", 1);
				uni.navigateTo({
					url: '/hyb_o2o/user/yhq/lq_yhq?yhq_type=1'
				})
			},

			closePopup() {
				this.$refs.bindPhone.close()
				uni.storage.set("tc_tag", 1);
			},

			goSearch() {
				if (this.search.trim().length > 0.1) {
					uni.navigateTo({
						url: "/hyb_o2o/shangjia/list/list?search=" + this.search
					})
				} else {
					uni.showToast({
						title: "至少输入两个字",
						icon: 'none'
					})
				}
			},

			to_position() {
				// if (this.$store.state.base.city_type == 1) {
				// 	uni.navigateTo({
				// 		url: '/hyb_o2o/shequ/list'
				// 	})
				// } else {
					uni.navigateTo({
						url: '/hyb_o2o/index/position'
					})
				// }

			},

			dingwei() {
				if (this.$store.state.base.show_base && this.$store.state.base.show_base.is_dingwei) {
					uni.location.getLocation().then((location) => {
						if (location) {
							this.$store.commit("set_location", location);
							uni.gPost("base/location", {
								latitude: location.latitude,
								longitude: location.longitude
							}).then((address) => {
								this.$store.commit("set_city", address.city);
								this.address = address;
							})
						}
					}).catch((e) => {
						uni.showToast({
							title: "定位失败!",
							icon: 'none'

						})
						// console.log(e)
					})
				}

			},


			goto(info) {

				if (info.lianjie == "phone") {
					const phoneNumbers = this.$store.state.base.phone.split('+');
					let phones = [phoneNumbers[0]];
					let itemList = [phoneNumbers[0]];

					if (phoneNumbers[1]) {
						phones.push(phoneNumbers[1]);
						itemList.push(phoneNumbers[1]);
					}

					if (this.$store.state.xiaoqu.s_tel) {
						phones.push(this.$store.state.xiaoqu.s_tel);
						itemList.push(this.$store.state.xiaoqu.name + "-" + this.$store.state.xiaoqu.s_tel);
					}

					if (phones.length === 1) {
						// 只有一个手机号码，直接拨号
						uni.makePhoneCall({
							phoneNumber: phones[0]
						});
					} else {
						// 有多个手机号码，弹出选择框
						uni.showActionSheet({
							itemList: itemList,
							success: (res) => {
								uni.makePhoneCall({
									phoneNumber: phones[res.tapIndex]
								});
							}
						});
					}
				} else if (info.lianjie.indexOf('http') == 0) {
					uni.navigateTo({
						url: '/hyb_o2o/h5/h5?src=' + encodeURIComponent(info.lianjie)
					})
				} else if (info.lianjie == 'kefu') {
					uni.makePhoneCall({
						phoneNumber: this.$store.state.base.phone
					});
				} else {
					uni.navigateTo({
						url: info.lianjie
					})
				}

			},

			get_pics() {
				uni.gPost("menu/top", {
					type: 4
				}).then((pics) => {
					this.pics = pics;
				})
			},

			get_tuijian_shangjia() {
				uni.gPost("shangjia/list", {
					location: uni.storage.get("location"),
					tuijian: 1
				}).then((shanjias) => {
					this.shanjias = shanjias;
				})
			},
			get_tuijian_good() {
				uni.gPost("goods/list", {
					g_tuijian: 1,
					location: uni.storage.get("location"),
				}).then((data) => {
					this.goods = data;
				})
			},

			get_tuijian_yuangong() {
				uni.gPost("yuangong/list", {
					y_tuijian: 1,
					location: uni.storage.get("location"),
				}).then((data) => {
					this.yuangongs = data;
				})
			},


			get_tuijian_fuwu() {
				uni.gPost("fuwu/list", {
					x_tuijian: 1
				}).then((res) => {
					this.fuwus = res.data;
				})
			},

			get_notices() {
				uni.gPost("gonggao").then((menus) => {
					let notices = [];
					menus.forEach((item) => {
						notices.push({
							url: item.lianjie,
							title: item.title,
						})
					})

					this.notices = notices;
				})
			},

			get_swipers() {
				uni.gPost("menu/top", {
					type: 1
				}).then((menus) => {
					let swiperItems = [];
					menus.forEach((item) => {
						swiperItems.push({
							img: item.thumb,
							url: item.lianjie,
							title: "",
							opentype: 'navigate'
						})
					})

					this.swiperItems = swiperItems;
				})
			},

			get_article_swipers() {
				uni.gPost("article/list", {
						is_tuijian: 1
					}).then((res) => {
						// 验证响应结构是否符合预期
						if (!res || !Array.isArray(res.data)) {
							console.error('文章列表数据格式错误:', res);
							return;
						}

						// 处理文章数据，添加防御性检查
						const swiperItems = res.data
							.filter(item =>
								item && item.id &&
								item.imgs && Array.isArray(item.imgs) && item.imgs.length > 0
							)
							.map(item => ({
								img: item.imgs[0], // 经过过滤后，此处访问安全
								// url: `/hyb_o2o/article/info/info?id=${item.id}`,
								title: item.title || '', // 添加默认值
								opentype: 'navigate'
							}));

						// 更新数据
						this.articleItems = swiperItems;

						// 可选：记录处理结果
						console.log(`成功加载 ${swiperItems.length} 篇推荐文章`);
					})
					.catch(error => {
						// 统一错误处理
						console.error('获取推荐文章失败:', error);
						uni.showToast({
							title: '获取文章列表失败',
							icon: 'none'
						});
					});
			},


			get_tops() {
				uni.gPost("menu/top", {
					type: 2
				}).then((tops) => {
					this.tops = tops;
				})
			},

			get_second_tops() {
				uni.gPost("menu/top", {
					type: 0
				}).then((tops) => {
					this.second_tops = tops;
				})
			},

			openMenuPopup() {
				this.showMenuPopup = true;
			},

			handleMenuSelect(type) {
				uni.gPost('user/save', {
					u_id: this.userinfo.u_id,
					type: type
				}).then(res => {
					this.showMenuPopup = false;
					uni.storage.set("menu_popup_shown", 1);
					// 重新载入到指定页面
					uni.reLaunch({
						url: '/hyb_o2o/tablist/index/index?tabinex=0&tabbar=1'
					});
				});
			}
		}
	}
</script>
<style scoped>
	.main {
		display: flex;
		flex-direction: column;
	}

	.gui-list-image {
		width: 160rpx;
		height: 160rpx;
		border: 2rpx solid #f0f0f0;
		border-radius: 10rpx;
	}

	.uni-input-placeholder {
		font-size: 20rpx;
	}

	.fake-popup {
		position: fixed;
		left: 0;
		top: 0;
		right: 0;
		bottom: 0;
		background: rgba(0, 0, 0, 0.4);
		z-index: 9999;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.popup-content {
		background: #fff;
		border-radius: 16rpx;
		padding: 40rpx 30rpx;
		min-width: 400rpx;
		text-align: center;
	}

	.menu-btn {
		width: 100%;
		margin: 20rpx 0;
		font-size: 32rpx;
		background: #f7f7f7;
		border-radius: 12rpx;
		padding: 24rpx 0;
		color: #333;
		border: none;
	}

	.menu-btn:active {
		background: #ffe4b5;
	}
</style>